package com.xushi.service.impl;

import com.xushi.dao.TemplateRepository;
import com.xushi.model.Template;
import com.xushi.service.TemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("templateService")
public class TemplateServiceImpl implements TemplateService {
    @Autowired
    private TemplateRepository templateDao;

    @Override
    public Template createTemplate(String username, String templateName, String title, String description, String serveUrl, String type, String backgroundImgPath) {
        Template template = new Template(username, templateName, title, description, serveUrl, type, backgroundImgPath);
        return templateDao.save(template);
    }

    @Override
    public Template getTemplate(String username, String templateName) {
        return templateDao.getTemplateByUsernameAndName(username, templateName);
    }

    @Override
    public List<Template> getTemplateListByUsername(String username) {
        return templateDao.getTemplatesByUsername(username);
    }

    @Override
    public Template getTemplateByName(String templateName) {
        return templateDao.getTemplateByName(templateName);
    }

    @Override
    public Template getTemplateById(int templateId) {
        return templateDao.getTemplateById(templateId);
    }

    @Override
    public Template updateTemplate(Template template) {
        return templateDao.save(template);
    }
}
